package com.regent.central.bill.service.bean;

import com.regent.central.bill.core.Clearance;
import com.regent.central.bill.repository.ClearanceMapper;
import com.regent.central.bill.service.ClearanceService;
import com.regent.central.infrastructure.service.bean.DomainServiceBean;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.List;

@Service
public class ClearanceServiceBean extends DomainServiceBean<ClearanceMapper, Clearance> implements ClearanceService {

    /**
     * 撤销核销记录
     *
     * @param clearanceId 核销记录ID
     */
    @Transactional(isolation = Isolation.READ_COMMITTED, propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
    @Override
    public void cancel(String clearanceId, String userCanceled) {
        mapper.cancel(clearanceId, userCanceled);
    }

    /**
     * 更新核销记录的核销金额
     *
     * @param clearanceId 核销记录ID
     * @param amount      核销金额
     * @param userId      操作人ID
     */
    @Transactional(isolation = Isolation.READ_COMMITTED, propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
    @Override
    public void update(String clearanceId, BigDecimal amount, String userId) {
        mapper.update(clearanceId, amount, userId);
    }

    /**
     * 获取销售单的核销记录
     *
     * @param saleOrderId 销售单ID
     * @return 销售单的核销记录
     */
    @Override
    public List<Clearance> getSaleOrderClearances(String saleOrderId) {
        return getSaleOrderClearances(saleOrderId, false, false);
    }

    /**
     * 获取销售单的核销记录
     *
     * @param saleOrderId 销售单ID
     * @param canceled    已撤销
     * @param deleted     已删除
     * @return 销售单的核销记录
     */
    @Override
    public List<Clearance> getSaleOrderClearances(String saleOrderId, Boolean canceled, Boolean deleted) {
        return mapper.getSaleOrderClearances(saleOrderId, canceled, deleted);
    }

}